<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <base href="<%=request.getContextPath()%>/"/>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <script src="static/js/jquery-2.1.1.min.js"></script>
    <%@include file="layUI.jsp"%>

</head>
<body>
<%--&id='${param.GoodsID}'--%>
<form  method="post" enctype="multipart/form-data" id="form" action="/doGoodsServlet?action=update">
    商品图像<table ><tr><td></td><input type="file" name="goodsImage"></tr></table>
    <di id="d1"></di>
    商品id<input type="text" value="" name="id" readonly="readonly" id="GoodsID">
    商品名称<input type="text" value="" name="goodsName" id="goodsName">
    小分类名称<select name="goodsSmalId" id="goodsSmalId">
    </select>
    商品的价格<input type="text" value="" name="goodsMoney" id="goodsMoney" >
    商品的数量<input type="text" value="" name="goodsNumber" id="goodsNumber" ><br>
    商品的运费<input type="text" value="" name="goodsCarriage" id="goodsCarriage" >
    商品的类型<select name="goodsType" id="goodsType">
    <option value="0">新品</option>
    <option value="1">二手</option>
</select>
    商家名称<select name="goodsSeId" id="goodsSeId">
</select>
    商品的折扣<select name="goodsDiscId" id="goodsDiscId">
</select>
    <input type="submit" value="修改完成" class="layui-btn" id="sub" onclick="Bullery()">
</form>
</body>

<script type="text/javascript">

    $(function () {
        addSmall();
        addDiscount();
        addSeller();
        addOption();
    })

    //往页面加载数据
    function addOption() {
        var GoodsID='${param.GoodsID}';
        $.getJSON("/doGoodsServlet","action=getGoodsID&GoodsID="+GoodsID,callback);
        function callback(data) {
            $("#GoodsID").val(data.id);
            $("#goodsName").val(data.goodsName);
            $("table tr").append("<img src='GoodsImage/"+data.goodsImage+"' >");
            $("#goodsMoney").val(data.goodsMoney);
            $("#goodsNumber").val(data.goodsNumber);
            $("#goodsCarriage").val(data.goodsCarriage);
            $("#goodsSeId").val(data.goodsSeId);
            $("select [value='"+data.goodsSmalId+"']").attr("selected",true);
            $("select [value='"+data.goodsSeId+"']").attr("selected",true);
            $("select [value='"+data.goodsDiscId+"']").attr("selected",true);
            $("select [value='"+data.goodsType+"']").attr("selected",true);
        }
    }
    
    //添加小分类的下拉列表
    function addSmall() {
        $.getJSON("/SmallServlet", "action=select", callback);
        function callback(data) {
            for (var i = 0; i <data.length ; i++) {
                $("[id=goodsSmalId]").append("<option value='" + data[i].smallId + "'>" + data[i].smallName + "</option>");
            }
        }
    }
    //添加折扣率的下拉列表
    function addDiscount() {
        $.getJSON("/SmallServlet", "action=select2", callback);
        function callback(data) {
            $(data).each(function () {
                $("[id=goodsDiscId]").append("<option value='" + this.id + "'>" + this.discRate + "</option>");
            })
        }
    }
    //添加商家名称的下拉列表
    function addSeller() {
        $.getJSON("/SmallServlet", "action=select1", callback);
        function callback(data) {
            $(data).each(function () {
                $("[id=goodsSeId]").append("<option value='" + this.id + "'>" + this.sellerName + "</option>");
            })
        }
    }
</script>
</html>
